package com.boang.controller;

import com.boang.domain.AskTags;
import com.boang.domain.AskTechnology;
import com.boang.resp.Result;
import com.boang.service.AskTechnologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
  @author: 13813
  @date: 2024/8/15 11:05
*/
@RestController
@RequestMapping("/technology")
public class AskTechnologyController {

    @Autowired
    private AskTechnologyService askTechnologyService;

    @RequestMapping("/getAskTechnologyList")
    public Result<List<AskTechnology>> getAskTechnologyList() {
        List<AskTechnology> list = askTechnologyService.list();

        List<AskTechnology> askTagList = list.stream().map(askTechnology -> {
            //查询关联的Tag
            List<AskTags> tags = askTechnologyService.getAskTagsByTechId(askTechnology.getId());
            //设置到AskTechnology对象中
            askTechnology.setTagsList(tags);
            //返回AskTechnology对象
            return askTechnology;
        }).toList();

        return Result.ok(askTagList);
    }
}
